package com.shopx.sys.controller;

import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.base.anno.ShopxParamAnno;
import com.shopx.base.controller.BaseController;
import com.shopx.base.dto.Result;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.utils.ResultUtil;
import com.shopx.cmm.DTO.PageDTO;
import com.shopx.core.common.CommonConstant;
import com.shopx.sys.bean.SysCompany;
import com.shopx.sys.dto.CpTreeShowDTO;
import com.shopx.sys.model.SysCompanyModel;
import com.shopx.sys.service.ISysCompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author lituo
 * @className: SysCompanyController
 * @date 2021-12-07
 */
@RestController
@Slf4j
@RequestMapping(value = "/sysCompany")
public class SysCompanyController extends BaseController {

    @Resource
    private ISysCompanyService sysCompanyService;

    /**
     * 企业列表查询（平台管理员）
     *
     * @param sysCompany
     * @return com.shopx.base.dto.Result<com.shopx.cmm.dto.PageDTO>
     * @author lituo
     * @date 10:42 AM 2021/12/12
     */
    @PostMapping(value = "/queryPageList")
    @ShopxParamAnno
    public Result<PageDTO> queryPageList(@RequestBody SysCompanyModel sysCompany) throws ShopxException {
        PageDTO<SysCompanyModel> pageDTO = sysCompanyService.getListPage(sysCompany);
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 企业申请入驻列表（平台管理员）
     *
     * @param sysCompany
     * @return com.shopx.base.dto.Result<com.shopx.cmm.dto.PageDTO>
     * @author lituo
     * @date 10:45 AM 2021/12/12
     */
    @PostMapping(value = "/queryApplyEnterList")
    @ShopxParamAnno
    public Result<PageDTO> queryApplyEnterList(@RequestBody SysCompanyModel sysCompany) throws ShopxException {
        PageDTO<SysCompanyModel> pageDTO = sysCompanyService.queryApplyEnterList(sysCompany);
        return ResultUtil.ok(pageDTO);
    }

    @PostMapping(value = "/queryEnterList")
    @ShopxParamAnno
    public Result<PageDTO> queryEnterList(@RequestBody SysCompanyModel sysCompany) throws ShopxException {
        PageDTO<SysCompanyModel> pageDTO = sysCompanyService.queryEnterList(sysCompany);
        return ResultUtil.ok(pageDTO);
    }

    @PostMapping(value = "/insertOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> insertOne(@RequestBody SysCompany sysCompany) throws ShopxException {
        String result = sysCompanyService.insertSelective(sysCompany);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/updateOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> updateOne(@RequestBody SysCompany sysCompany) throws ShopxException {
        int result = sysCompanyService.updateByPrimaryKeySelective(sysCompany);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/queryOneByPrimaryKey")
    public Result<SysCompanyModel> queryOneByPrimaryKey(@RequestBody SysCompany sysCompany) throws ShopxException {
        SysCompanyModel result = sysCompanyService.selectByPrimaryKey(sysCompany);
        return ResultUtil.ok(result);
    }


    @PostMapping(value = "/giveOrder")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<?> giveOrder(@RequestBody SysCompany sysCompany) throws ShopxException {
        sysCompanyService.giveOrder(sysCompany);
        return ResultUtil.ok(true);
    }

    @PostMapping(value = "/offline")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<?> offline(@RequestBody SysCompany sysCompany) throws ShopxException {
        sysCompanyService.offline(sysCompany);
        return ResultUtil.ok(true);
    }

    @PostMapping(value = "/online")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<?> online(@RequestBody SysCompany sysCompany) throws ShopxException {
        sysCompanyService.online(sysCompany);
        return ResultUtil.ok(true);
    }

    /**
     * @return com.shopx.base.dto.Result<?>
     * @descript 查询企业明细信息
     * @author lituo
     * @date 2021/12/28 13:50
     */
    @PostMapping(value = "/entDetail")
    @ShopxParamAnno
    public Result<?> entDetail() throws ShopxException {
        SysCompanyModel model = sysCompanyService.entDetail();
        return ResultUtil.ok(model);
    }

    /**
     * @param sysCompany
     * @return com.shopx.base.dto.Result<?>
     * @descript 企业管理员保存企业信息
     * @author lituo
     * @date 2021/12/28 13:52
     */
    @PostMapping(value = "/entUpdate")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<?> entUpdate(@RequestBody SysCompany sysCompany) throws ShopxException {
        sysCompanyService.entUpdate(sysCompany);
        return ResultUtil.ok(true);
    }

    @PostMapping(value = "/selectCpTree")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<?> selectCpTree(@RequestBody SysCompany sysCompany) throws ShopxException {
        List<CpTreeShowDTO> list = sysCompanyService.selectCpTree(sysCompany);
        return ResultUtil.ok(list);
    }

	/*@PostMapping(value = "/deleteChecked")
	@RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)   @ShopxParamAnno
public Result<Integer> deleteChecked(@RequestBody SysCompany sysCompany) throws ShopxException {
		int result = sysCompanyService.deleteByPrimaryKey(sysCompany);
		return ResultUtil.ok(result);
	}*/
}

